package com.caigou.controller;

import com.caigou.bean.cms.param.AdConfigParam;
import com.caigou.bean.exam.entity.Users;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.AdConfigService;
import com.caigou.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api("广告管理器")
@RestController
@RequestMapping("/adConfig/")
public class AdConfigController {

    @Resource
    private AdConfigService adConfigService;

    @ApiOperation("获取广告配置类列表接口")
    @RequestMapping("loadAdConfigList")
    @PreAuthorize("hasAnyAuthority('guanggaohetong')")
    public Result loadAdConfigList(@RequestBody AdConfigParam param){
        return adConfigService.loadAdConfigList(param);
    }

    @ApiOperation("获取导出统计数据接口")
    @RequestMapping("loadAdConfigExportList")
    @PreAuthorize("hasAnyAuthority('daochutongjishuju')")
    public Result loadAdConfigExportList(@RequestBody AdConfigParam param){
        return adConfigService.loadAdConfigExportList(param);
    }

    @ApiOperation("批量根据广告位替换成默认广告")
    @RequestMapping("updateAdvertAdType")
    @PreAuthorize("hasAnyAuthority('guanggaoshezhi')")
    public Result updateAdConfigAdType(@RequestBody AdConfigParam param, @CurrentUser Users users){
        return adConfigService.updateAdConfigAdType(param,users);
    }

    @ApiOperation("获取广告位配置详情数据")
    @RequestMapping("loadAdConfigInfo")
    @PreAuthorize("hasAnyAuthority('guanggaohetong')")
    public Result loadAdConfigInfo(@RequestBody AdConfigParam param){
        return adConfigService.loadAdConfigInfo(param);
    }

    @ApiOperation("新增预设广告")
    @RequestMapping("saveAdList")
    @PreAuthorize("hasAnyAuthority('guanggaoshezhi')")
    public Result saveAdList(@RequestBody AdConfigParam param, @CurrentUser Users users){
        return adConfigService.saveAdList(param,users);
    }

    @ApiOperation("获取预设广告信息(编辑广告)")
    @RequestMapping("loadAdListInfo")
    @PreAuthorize("hasAnyAuthority('guanggaoshezhi')")
    public Result loadAdListInfo(@RequestBody AdConfigParam param){
        return adConfigService.loadAdListInfo(param);
    }

    @ApiOperation("编辑(修改)预设广告")
    @RequestMapping("updateAdListInfo")
    @PreAuthorize("hasAnyAuthority('guanggaoshezhi')")
    public Result updateAdListInfo(@RequestBody AdConfigParam param, @CurrentUser Users users){
        return adConfigService.updateAdListInfo(param,users);
    }

    @ApiOperation("下架预设广告(参数名为ID，广告的ID)")
    @RequestMapping("updateAdListStatus")
    @PreAuthorize("hasAnyAuthority('guanggaoshezhi')")
    public Result updateAdListStatus(@RequestBody AdConfigParam param, @CurrentUser Users users){
        return adConfigService.updateAdListStatus(param,users);
    }

    @ApiOperation("删除预设广告(参数名为ID，广告的ID)")
    @RequestMapping("deleteAdList")
    @PreAuthorize("hasAnyAuthority('guanggaoshezhi')")
    public Result deleteAdList(@RequestBody AdConfigParam param, @CurrentUser Users users){
        return adConfigService.deleteAdList(param,users);
    }

    @ApiOperation("关闭/开启广告位")
    @RequestMapping("updateAdConfigStatus")
    @PreAuthorize("hasAnyAuthority('guanggaoshezhi')")
    public Result updateAdConfigStatus(@RequestBody AdConfigParam param, @CurrentUser Users users){
        return adConfigService.updateAdConfigStatus(param,users);
    }

    @ApiOperation("获取操作记录")
    @RequestMapping("loadOperationList")
    @PreAuthorize("hasAnyAuthority('guanggaohetong')")
    public Result loadOperationList(@RequestBody AdConfigParam param){
        return adConfigService.loadOperationList(param);
    }
}
